package logic

import (
	"1-8zy/rpc/model/mysql"
	"context"
	"fmt"

	"1-8zy/rpc/internal/svc"
	"1-8zy/rpc/shop"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *shop.OrderListRequest) (*shop.OrderListResponse, error) {
	// todo: add your logic here and delete this line
	o := mysql.Order{}
	order, err := o.GetOrder(int(in.Page), int(in.PageSize))
	if err != nil {
		return nil, fmt.Errorf("查询错误")
	}
	var orders []*shop.OrderList
	for _, o2 := range order {
		orders = append(orders, &shop.OrderList{
			UserId:      int64(o2.UserId),
			GoodsId:     int64(o2.GoodsId),
			OrderSn:     o2.OrderSn,
			Amount:      float32(o2.Amount),
			Num:         int64(o2.Num),
			GoodsTitle:  o2.GoodsTitle,
			GoodsImage:  o2.GoodsImage,
			OrderStatus: int64(o2.OrderStatus),
			Payment:     int64(o2.Payment),
			Id:          int64(o2.ID),
		})
	}
	return &shop.OrderListResponse{
		Order: orders,
	}, nil
}
